package com.xinqi.modules.sys.dict.controller.web;

import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.sys.dict.dto.req.DictTypeCreateDTO;
import com.xinqi.modules.sys.dict.dto.req.DictTypeQueryDTO;
import com.xinqi.modules.sys.dict.dto.req.DictTypeUpdateDTO;
import com.xinqi.modules.sys.dict.dto.rsp.DictTypeResultDTO;
import com.xinqi.modules.sys.dict.service.DictTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 字典类型表WEB控制层
 *
 * @author: linkai
 * @date: 2023/05/21
 */
@Tag(name = "Web-字典类型表", description = "字典类型表Web接口")
@RestController
@RequestMapping("/web/dict-type")
@RequiredArgsConstructor
public class DictTypeWebController {
    private final DictTypeService dictTypeService;

    /**
     * 字典类型表-分页
     */
    @Operation(summary = "字典类型表-分页")
    @GetMapping("/page")
    public R<PageInfo<DictTypeResultDTO>> page(@ParameterObject DictTypeQueryDTO dto) {
        PageInfo<DictTypeResultDTO> page = dictTypeService.page(dto, dto);
        return R.data(page);
    }

    /**
     * 字典类型表-详情
     */
    @Operation(summary = "字典类型表-详情")
    @GetMapping("/{id}")
    public R<DictTypeResultDTO> findById(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id) {
        DictTypeResultDTO dto = dictTypeService.findById(id);
        return R.data(dto);
    }

    /**
     * 新增字典类型表
     */
    @Operation(summary = "新增字典类型表")
    @PostMapping
    public R<Long> insert(@RequestBody DictTypeCreateDTO dto) {
        return R.data(dictTypeService.insert(dto));
    }

    /**
     * 修改字典类型表
     */
    @Operation(summary = "修改字典类型表")
    @PutMapping("/{id}")
    public R<Boolean> update(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id,
                             @RequestBody DictTypeUpdateDTO dto) {
        dto.setId(id);
        return R.data(dictTypeService.updateById(dto));
    }

    /**
     * 删除字典类型表
     */
    @Operation(summary = "删除字典类型表")
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id) {
        return R.data(dictTypeService.deleteById(id));
    }

}
